package com.iot08.api.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iot08.common.entity.app.Questions;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.CollectionUtil;
import com.iot08.common.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 问题类别
 * @author weichao 1299101858@qq.com
 * @version 1.0
 * @date 4/29/22 2:40 PM
 */
@Slf4j
@Service
public class QuestionService extends BaseService<Questions> {
    /**
     * 获取类别
     * @time: 4/29/22 5:55 PM
     * @author: Weichao
     * @version 1.0
     */
    public List getDataList () {
        List<Map<String, Object>> arr = new ArrayList<>();
        List<Questions> questions = this.find(new Query());
        for (Questions item : questions) {
            Map<String, Object> tempItem = new HashMap<>();
            tempItem.put("index", item.getIndex());
            tempItem.put("category", item.getCategory());
            tempItem.put("categoryid", item.getCategoryid());
            arr.add(tempItem);
        }
        //根据 index 降序排序
        CollectionUtil.sortDouble(arr, "index", 2);


        return arr;
    }
}
